package a5;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class WordAlphabizer {

	public static void main(String[] args) 
	{
		String[] words = new String[10000];
		try {
			FileReader fileReader = new FileReader("10kwords.txt");
			BufferedReader bufferedReader = new BufferedReader(fileReader);
			String longest="a";
			for (int i = 0; i < 10000; i++) 
			{
				String oneLine = bufferedReader.readLine();
				words[i] = oneLine;
				boolean check = isWordAlphabetized(words[i]);		// is it alphabetized
				if (check && longest.length() < words[i].length())	// finding the longest one
						longest = words[i];
			}
//			System.out.println(longest);     // original most common longest word is access
			for (int i = 0; i < 10000; i++) 			
			if( isWordAlphabetized(words[i]) && words[i].length()== longest.length())
			{
				
				System.out.println(words[i]);
			}
				
			
		} catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		} catch (IOException e) 
		{
			e.printStackTrace();
		}

	}

	public static boolean isWordAlphabetized(String word) 
	{
		for (int i = 1; i < word.length(); i++) 
		{
			if (word.charAt(i) <=/*equal sign added here*/ word.charAt(i - 1)) 
			{
				return false;
			}
		}
		return true;
	}
}
